package com.loongtech.bi.manager.player;

import com.loongtech.bi.entity.player.EntityNotIdfaNewUser;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NotIdfaNewUserManager extends ManagerQueryCacheBase<EntityNotIdfaNewUser> {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 根据开始结束时间查询所有新增用户数据
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<EntityNotIdfaNewUser> getNewUsersByDate(Date dateStart, Date dateEnd) {
		return findByQuery("from EntityNotIdfaNewUser where 1=1 and day>=:dayStart and day<=:dayEnd order by day ", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据开始结束时间查询某个维度的数值
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getNewUserByAllKind(Date dateStart, Date dateEnd,String queryPlatform, String queryChannel, String queryServer) {
		return findByQuery("select date_format(day,'%Y-%m-%d'),new_user from EntityNotIdfaNewUser where day>=:dayStart and day<=:dayEnd and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' and new_user is not null group by day order by day desc", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据platformid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getNewUserGroupByPlatform(Date dateStart, Date dateEnd) {
		return findByQuery("select platformid,sum(new_user) from EntityNotIdfaNewUser where day>=:dayStart and day<=:dayEnd and platformid != '0' and new_user is not null group by platformid", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据channelid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getNewUserGroupByChannel(Date dateStart, Date dateEnd) {
		return findByQuery("select channelid,sum(new_user) from EntityNotIdfaNewUser where day>=:dayStart and day<=:dayEnd and channelid != '0' and new_user is not null group by channelid", "dayStart", dateStart, "dayEnd", dateEnd);
	}
	
	/**
	 * 根据serverid 查询
	 * @param dateStart
	 * @param dateEnd
	 * @return
	 */
	public List<Object[]> getNewUserGroupByServer(Date dateStart, Date dateEnd) {
		return findByQuery("select serverid,sum(new_user) from EntityNotIdfaNewUser where day>=:dayStart and day<=:dayEnd and serverid != '0' and new_user is not null group by serverid", "dayStart", dateStart, "dayEnd", dateEnd);
	}
}
